import Cookies from "js-cookie";

class LoginUtil {
  //登录时的参数
  static loginParam: any = null;
  static isRefreshLogin: boolean = false;
  static instance: LoginUtil | null = null;
  static getInstance() {
    return this.instance ?? (this.instance = new LoginUtil());
  }

  /**
   * 标识当前是续期登录
   * @param re
   */
  setRefreshLogin(re: boolean) {
    LoginUtil.isRefreshLogin = re;
  }
  setLoginParams(params: any) {
    LoginUtil.loginParam = params;
    //同时保存到cookie中
    localStorage.setItem("login-params", params);
    console.log("保存登录参数成功");
  }
  isRefreshToken() {
    return LoginUtil.isRefreshLogin;
  }
  getLoginParams() {
    return LoginUtil.loginParam ?? localStorage.getItem("login-params");
  }
}

const loginUtil = LoginUtil.getInstance();

export default loginUtil;
